package com.xsdl.chain.verifier;

import com.xsdl.chain.annonation.Min;

import java.lang.reflect.Field;

public class MinVerifier implements Validator {

    @Override
    public void validate(Field field, Object value, ValidatorContext context) {
        Min min = field.getAnnotation(Min.class);
        if (min != null) {
            int minValue = min.value();
            if (value instanceof Integer) {
                int v = (Integer) value;
                if (v < minValue) {
                    context.appendErrMsg(field.getName() + "当前值为:" + v + ",小于最小值:" + minValue);
                }
            }
        }
    }

}
